//封装axios请求
class Axios {
    post(url, data) {
      return this.request("POST", url, data)
    }
    get(url, data) {
      return this.request("GET", url, data)
    }
    put(url, data) {
      return this.request("PUT", url, data)
    }
    update(url, data) {
      return this.request("UPDATE", url, data)
    }
    detete(url, data) {
      return this.request("DELETE", url, data)
    }
    request(method, url, data) {
      return new Promise((resolve, reject) => { 
        wx.request({
          url: url,
          method:method,
          data:data,
          header: {
            "content-type": 'application/json'//默认值
          },
          success(res) {
            console.log(res.data);//打印返回的数据
            resolve(res.data)
          },
          fail(err) {
            reject(err)
          }
        })
      })
    }
  }
  module.exports = new Axios();//将其暴露出去